<?php
if (!ob_start("ob_gzhandler")) {
  ob_start();
}

require_once '../include/config.php';
require_once '../include/utils.class.php';
require_once '../include/orm.class.php';

$__sys = Utils::get_param('__sys', NULL);
$__inst = Utils::get_param('__inst', NULL);

$session_id = Utils::get_param('PHPSESSID', NULL);

if ($session_id) {
  session_id($session_id);
  session_start();
} else {
  session_name(SESSION);
  session_start();
}

if (!isset($_SESSION[SYS . $__sys])) {
  die('Session Not Found');
}

$app_data = $_SESSION[SYS . $__sys];
$inst = $app_data->instances[$__inst];

if (!in_array($inst->__folder, $app_data->plugins)) {
  die('Acceess Denied');
}

if ($app_data->sys->login_required == 1 && (!(isset($app_data->is_authorised)) || $app_data->is_authorised == 0) && !in_array($inst->__folder, $app_data->exceptions)) {
  die('Not Authenticated');
}

$tmpl = Utils::get_param('tmpl', NULL);
$tmpl_id = Utils::get_param('id', NULL);
$orm = new ORM();
require_once "../include/colg/inc.print.$tmpl.php";

function ____setup($doc, $obj) {
  foreach ($obj as $key => $val) {
    $elms = explode('-', $val);
    if (count($elms) == 3 && checkdate($elms[1], $elms[2], $elms[0])) {
      $val = date('d M Y', strtotime($val));
    }
    if (strpos($key, 'total') !== false || strpos($key, 'fee') !== false || strpos($key, 'amount') !== false || strpos($key, 'balance') !== false) {
      $val = utf8_encode('$') . number_format($val, 2);
    }
    $doc->setValue($key, $val);
  }
}
?>